<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		#box{
			width: 200px;
			height: 200px;
			background: red url() 0 0 no-repeat;
		}
	</style>
	<script>
		
		window.onload=function () {
			box = document.getElementById('box')
			btn = document.getElementById('btn')

			is = true;

			btn.onclick= function(){
				if(is){
					btn.innerHTML ="停止";
					time = setInterval(run,5)
					is = false;
				}else{
					clearInterval(time)
					btn.innerHTML ="开始";
					is= true;
				}
			}

			width = 200;

			fanxiang = true;
			function run() {

				if(width<200){
					fanxiang = true;
				}else if(width>400){
					fanxiang = false;
				}

				if(fanxiang){
					width += 1;
				}else{
					width -= 1;
				}

				box.style.width = width+"px";
				box.style.height = width+"px";
			}
		}

	</script>
</head>
<body>
	<button id="btn">开始</button>
	<div id="box"></div>
	
</body>
</html>